/* ABINLOAD.c by bill buckels 2008        */
/* a picture viewer for the apple II      */
/* written in Manx Aztec C65 Version 3.2b */
/* runs under DOS 3.3                     */
/* displays BSaved HIRES Images           */

extern char XPIC;
extern char YPIC;

main()
{
	char picname[66], R, A, G;
	int c, bsaved, idx;

 	setcrtmode(2);

 if (getch()!=27) {
	 for (;;) {
		blue();
		setcrtmode(0);
		for (;;) {
			scr_apple();
			catalog();
			printf("Enter Pic Name: ");
			gets(picname); /* get the filename */
			if (picname[0] == 0)break;
			scr_apple();
			printf("Please Wait! Now loading...\n");

			bsaved = 1;
			for (idx = 0; picname[idx] != 0; idx++) {
				if (picname[idx] != '.')continue;
				R = picname[idx + 1];
				A = picname[idx + 2];
				G = picname[idx + 3];
				if (R == 'R' && A == 'A' && G == 'G') {
					bsaved = 0;
					break;
				}
				if (R == 'T' && A == 'O' && G == 'P') {
					bsaved = 0;
					break;
				}
				if (R == 'B' && A == 'O' && G == 'T') {
					bsaved = 0;
					break;
				}
			}
			/* signal centre image on screen */
			XPIC = 40;
			YPIC = 192;
			if (bsaved == 0) c = piclode(picname);
			else c = bload(picname);

			if (c==0)break;

			bellerr();
			if (c == -1) printf("! Can't open %s\n",picname);
			else printf("! %s wrong format!\n",picname);
			printf("Press Any Key...");
			getch();

		}
		if (picname[0] == 0)break;
		setcrtmode(2);
		if(getch()==27)break;
	}
  }
  setcrtmode(0);
  scr_apple();
  reboot();
}


